using System;
using System.Text;
using ApiProject.Api.Entity;
using ApiProject.Api.PramaModel;
using Microsoft.IdentityModel.Tokens;
using System.Security.Claims;
using System.IdentityModel.Tokens.Jwt;

namespace ApiProject.Api.Uitls
{
    public class TokenHelper{

        public static string GetToken(Token tokenParam , dynamic users){
            var claims = new[]
            {
                new Claim("username", users.Username),
                new Claim(ClaimTypes.Role, "admin"),
            };

            var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(tokenParam.Secret));
            var credentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
            var jwtToken = new JwtSecurityToken(tokenParam.Issuer, null, claims, expires: DateTime.UtcNow.AddMinutes(tokenParam.AccessExpiration), signingCredentials: credentials);

            var token = new JwtSecurityTokenHandler().WriteToken(jwtToken);

            return token;
        }
        
    }
}
